<?php

declare(strict_types=1);

namespace app\common\model\auth;

use Dengje\Pxy\BaseModel;

class RolePermissionModel extends BaseModel
{
    protected $name = 'role_permission';
    protected $autoWriteTimestamp = false;

    /**
     * 更新
     */
    public static function updateRel($roleId,array $permIds)
    {
        // 删除
        self::where('role_id',$roleId)->delete();
        // 因为前端不带父级的id这里加上
        $data = [];
        foreach($permIds as $v){
            $data[] = [
                'role_id' => $roleId,
                'code' => $v
            ];
        }
        // 插入
        self::insertAll($data);
    }
}